<?php
require('includes/application_top.php');
//mail subject
 $i=0;
 $configuration_query = tep_db_query("select configuration_id, configuration_title, configuration_value, use_function from " . TABLE_CONFIGURATION . " where configuration_group_id = 1 order by sort_order");
  while ($configuration = tep_db_fetch_array($configuration_query)) {
    if (tep_not_null($configuration['use_function'])) {
      $use_function = $configuration['use_function'];
      if (ereg('->', $use_function)) {
        $class_method = explode('->', $use_function);
        if (!is_object(${$class_method[0]})) {
          include(DIR_WS_CLASSES . $class_method[0] . '.php');
          ${$class_method[0]} = new $class_method[0]();
        }
        //$cfgValue = tep_call_function($class_method[1], $configuration['configuration_value'], ${$class_method[0]});
      } else {
        //$cfgValue = tep_call_function($use_function, $configuration['configuration_value']);
      }
    } else {
      $cfgValue[$i] = $configuration['configuration_value'];$i++ ;
    }



    if ( (isset($cInfo) && is_object($cInfo)) && ($configuration['configuration_id'] == $cInfo->configuration_id) ) {
      echo '                  <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_CONFIGURATION, 'gID=' . $HTTP_GET_VARS['gID'] . '&cID=' . $cInfo->configuration_id . '&action=edit') . '\'">' . "\n";
    } else {
      echo '                  <tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_CONFIGURATION, 'gID=' . $HTTP_GET_VARS['gID'] . '&cID=' . $configuration['configuration_id']) . '\'">' . "\n";
    }


  }
$mail='From: Shop_Order_From--'.$HTTP_POST_VARS["email"];
$subject= "Order Number No:";
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .=  $mail;
$to= $cfgValue[1]."<".$cfgValue[2].">";
?>

<html>
<head>
<meta http-equiv="Content-Language" content="he">
<meta http-equiv="Content-Type" content="text/html; charset=windows0255">
<title><?php echo $cfgValue[0]; ?></title>
</head>

<body>
    <center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="650" id="AutoNumber1">
  <hr color="#000000" size="1">
  <tr>
   <td width="34%">
      <p align="center"><b><font face="Times New Roman" size="4"><u><?php echo $cfgValue[0]; ?></u><br>
        Computer System</font></b>
         </td>
         <tr>
    <td width="37%">
      <p align="center"><b><font face="Verdana" size="2">

       Address: <?php echo $cfgValue[12]; ?><br>
        Email :<?php echo $cfgValue[2]; ?></font></b>
    </td>
    </tr>
  </tr>
  <tr>
    <td colspan="3">
      <hr color="#000000" size="1">
      <br>
      <table border="1" align="center" cellpadding="0" cellspacing="5" style="border-collapse: collapse" bordercolor="#111111" width="645" id="AutoNumber2">
        <tr>
          <td width="16"><strong></strong></td>
          <td width="137"><strong>Part type</strong></td>
          <td width="473">
            <p align="center"><strong>Part name</strong><span lang="en-us"> <strong>/ Price</strong></span>
          </td>
          <td width="52">
            <p align="center"><strong>Amount</strong>
          </td>
        </tr>
<?php
$InsertProducts=($HTTP_POST_VARS["product"]);
$InsertQTY=$HTTP_POST_VARS["ammount"];
    // echo $InsertQTY;
     //echo $InsertProducts;
     //echo $mail;
     $InP=$InsertProducts;
     $InQ= $InsertQTY;
     $InsertProducts=explode("::",$InsertProducts);
       $InsertQTY=explode("::",$InsertQTY);

$message= '
   <html>
<head>

<title>Expert-Communication</title>

</head>

<body>
      <center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="650" id="AutoNumber1">
  <hr color="#000000" size="1">
  <tr>
     <td width="34%">
      <p align="center"><b><font face="Times New Roman" size="4"><u>'.$cfgValue[0].'</u><br>
        Computer System</font></b>
         </td>
         <tr>
    <td width="37%">
      <p align="center"><b><font face="Verdana" size="2">

       Address:'.$cfgValue[12].'<br>
        Email : '.$cfgValue[2].'</font></b>
    </td>
    </tr>
  </tr>
  <tr>
    <td colspan="3">
      <hr color="#000000" size="1">
      <br>
      <table border="1" align="center" cellpadding="0" cellspacing="5" style="border-collapse: collapse" bordercolor="#111111" width="645" id="AutoNumber2">
        <tr>
          <td width="16"><strong></strong></td>
          <td width="137"><strong>Part type</strong></td>
          <td width="473">
            <p align="center"><strong>Part name</strong><span lang="en-us"> <strong>/ Price</strong></span>
          </td>
          <td width="52">
            <p align="center"><strong>Amount</strong>
          </td>
        </tr>';

// Be sure sql tables exist again ;P
if( mysql_num_rows(mysql_query("SHOW TABLES LIKE 'compbuild_options'"))==1){



//get builder options
$cbcomp_query = tep_db_query("select * from `compbuild_options`");
 while ($cbcomp = tep_db_fetch_array($cbcomp_query)){
$pc_system_id= $cbcomp['pc_system_id'];
$pc_system_name= $cbcomp['pc_system_name'];
$pc_system_image= $cbcomp['pc_system_image'];
$pc_system_language= $cbcomp['pc_system_language'];
$pc_system_assembly= $cbcomp['pc_system_assembly'];
$pc_template= $cbcomp['pc_template'];
$pc_use_osc_cart= $cbcomp['pc_use_osc_cart'];
$pc_add_tax= $cbcomp['pc_add_tax'];
$pc_use_dependence= $cbcomp['pc_use_dependence'];
$pc_use_software= $cbcomp['pc_use_software'];
$pc_currency= $cbcomp['pc_currency'];
}
//get builder categories
 $pcount=0;
     $bcomp_query = tep_db_query("select * from `compbuild_categories` ORDER BY pc_category_id");
 while ($bcomp = tep_db_fetch_array($bcomp_query)){
$pcid[$pcount]= $bcomp['pc_category_id'];
$pccat[$pcount]= $bcomp['pc_category_name'];
$pcimg[$pcount]= $bcomp['pc_category_image'];
$osccat[$pcount]= $bcomp['osc_category_id'];
$pcdep[$pcount]= $bcomp['pc_depends_on'];
$msys_id[$pcount]= $bcomp['pc_system_id'];
$presets[$pcount]= $bcomp['pc_preset_ids'];
$pclang[$pcount]= $bcomp['pc_language'];



$message .='<tr>
          <td width="16"></td>
          <td width="137">'.$pccat[$pcount].'</td>
          <td width="473">'.$InsertProducts[$pcount].'</td>
          <td width="52" align="center">'.$InsertQTY[$pcount].'</td>
           </tr>';

$pcount++; }
echo $message;
} else { echo "<table bgcolor=\"red\"><tr><td><font color=\"yellow\"><B>Tables may not exist, or Database Error</B></font></td></tr></table>"; exit(); }
?>
      </table>
      <br>
    </td>
  </tr>
  <tr>
    <td colspan="3">
      <table border="1" align="center" cellpadding="0" cellspacing="5" style="border-collapse: collapse" bordercolor="#111111" width="66%" id="AutoNumber3">
        <tr>
          <td width="36%">NIS <font face="David"><span lang="en-us">: </span><?php echo $HTTP_POST_VARS["sum"]; ?> 
            </font></td>
          <td width="87%"></td>
        </tr>
        <tr>
          <td width="73%">Each Payment <span lang="en-us">: <font face="David"><?php echo $HTTP_POST_VARS["each"]; ?> </font>
            </span></td>
          <td width="50%"><font face="David">Payments: <?php echo $HTTP_POST_VARS["payments"]; ?></font></td>
        </tr>
        <tr>
          <td width="123%" colspan="2"><span lang="en-us">Payments Fee </span><font face="David">
            :<span lang="en-us"> </span><?php echo $HTTP_POST_VARS["fee"]; ?>  </font></td>
        </tr>
        <tr>
          <td width="123%" colspan="2">Delivery<span lang="en-us"> : </span><font face="David"><?php echo $HTTP_POST_VARS["delivery_price"]; ?>  </font>
                  </td>
        </tr>
        <tr>
          <td width="123%" colspan="2"><b><font size="4">Total Price<span lang="en-us">
            :</span> </font><font size="4" face="David"><?php echo $HTTP_POST_VARS["totsum"]; ?>  </font></b></td>
        </tr>
      </table>
    </td>
  </tr>
    <tr>
    <td colspan="3"> <br>
      <hr color="#000000" size="1">
      <table align="center" width="54%" border="0">
        <tr>
          <td>     <center>
            Prices are valid for online order only.
              All prices include 18% Tax.</center>
          </td>
        </tr>
      </table>
      <hr color="#000000" size="1">
  <?php //---------------------------------------------------------------------------------------------
  $m75=' <tr>
    <td colspan="3">
      <table border="1" align="center" cellpadding="0" cellspacing="5" style="border-collapse: collapse" bordercolor="#111111" width="66%" id="AutoNumber3">
        <tr>
          <td width="36%">NIS <font face="David"><span lang="en-us">: </span>'. $HTTP_POST_VARS["sum"].' 
            </font></td>
          <td width="87%"></td>
        </tr>
        <tr>
          <td width="73%">Each Payment <span lang="en-us">: <font face="David">'. $HTTP_POST_VARS["each"].' </font>
            </span></td>
          <td width="50%"><font face="David">Payments: '. $HTTP_POST_VARS["payments"].'</font></td>
        </tr>
        <tr>
          <td width="123%" colspan="2"><span lang="en-us">Payments Fee </span><font face="David">
            :<span lang="en-us"> </span>'. $HTTP_POST_VARS["fee"].'  </font></td>
        </tr>
        <tr>
          <td width="123%" colspan="2">Delivery<span lang="en-us"> : </span><font face="David">'. $HTTP_POST_VARS["delivery_price"].'  </font>
                  </td>
        </tr>
        <tr>
          <td width="123%" colspan="2"><b><font size="4">Total Price<span lang="en-us">
            :</span> </font><font size="4" face="David">'. $HTTP_POST_VARS["totsum"].'  </font></b></td>
        </tr>
      </table>
    </td>
  </tr>
    <tr>
    <td colspan="3"> <br>
      <hr color="#000000" size="1">
      <table align="center" width="54%" border="0">
        <tr>
          <td>     <center>
            Prices are valid for online order only.
              All prices include 18% Tax.</center>
          </td>
        </tr>
      </table>
      <hr color="#000000" size="1">';
      $m76='<tr>
    <td colspan="3"> <br>
      <table border="2" align="center" cellpadding="0" cellspacing="5" style="border-collapse: collapse" bordercolor="#111111" width="80%" id="AutoNumber3">
        <tr>
          <td width="50%" ><b>Name & Last Name <font face="David"><span lang="en-us">: </b></span>'. $HTTP_POST_VARS["firstname"].' '. $HTTP_POST_VARS["lastname"].'
            </font></td>
          <td width="50%"></td>
        </tr>
        <tr>
          <td width="73%"><b>Address  <span lang="en-us">: </b><font face="David">'. $HTTP_POST_VARS["address"].'</font>
            </span></td>
          <td width="50%"><b>City : </b>'. $HTTP_POST_VARS["city"].'</td>
        </tr>
        <tr>
          <td width="123%" colspan="2"><span lang="en-us"><b>E-mail </span><font face="David">
            :</b><span lang="en-us"> </span>'. $HTTP_POST_VARS["email"].' </font></td>
        </tr>
        <tr>
          <td width="123%" colspan="2"><b>Telephone</b><span lang="en-us"> : </span><font face="David">'. $HTTP_POST_VARS["tel"]. '<b>Mobile : </b>'. $HTTP_POST_VARS["mobile"].' </font>
                  </td>
        </tr>

      </table>
    </td>
  </tr>
   </td>
  </tr>
</table>
 </body>
</html>';

  ?>

  <tr>
    <td colspan="3"> <br>
      <table border="2" align="center" cellpadding="0" cellspacing="5" style="border-collapse: collapse" bordercolor="#111111" width="80%" id="AutoNumber3">
        <tr>
          <td width="50%" ><b>Name & Last Name <font face="David"><span lang="en-us">: </b></span><?php echo $HTTP_POST_VARS["firstname"];echo ' ';echo $HTTP_POST_VARS["lastname"];  ?>
            </font></td>
          <td width="50%"></td>
        </tr>
        <tr>
          <td width="73%"><b>Address  <span lang="en-us">: </b><font face="David"><?php echo $HTTP_POST_VARS["address"]; ?></font>
            </span></td>
          <td width="50%"><b>City : </b><?php echo $HTTP_POST_VARS["city"]; ?></td>
        </tr>
        <tr>
          <td width="123%" colspan="2"><span lang="en-us"><b>E-mail </span><font face="David">
            :</b><span lang="en-us"> </span><?php echo $HTTP_POST_VARS["email"]; ?> </font></td>
        </tr>
        <tr>
          <td width="123%" colspan="2"><b>Telephone</b><span lang="en-us"> : </span><font face="David"><?php echo $HTTP_POST_VARS["tel"]; echo '           <b>Mobile : </b>';echo $HTTP_POST_VARS["mobile"];?> </font>
                  </td>
        </tr>

      </table>
    </td>
  </tr>

  <tr>
    <td colspan="3"> <br>
      <hr color="#000000" size="1">
      <table align="center" width="54%" border="0">
        <tr>
          <td>     <center>
            Please check your address and telephone cause without telephone permision
            we will cancel this order after two weeks!!!
          </td>
        </tr>
      </table>
      <br>
<?php //creating file
 $fp = fopen("./mail.htm", "w");
  fwrite( $fp,$message);
  fwrite( $fp, $m75);// payment types
  fwrite( $fp, $m76);// shipping
  $filename = "./mail.htm";
  $fd = fopen( $filename, "rb" );
  $contents = fread( $fd, 15000 );
  fclose( $fd );
 ?>
      <hr color="#000000" size="1">
      <form method="post" name="main">
        <p align="center" dir="ltr">
          <input type="button" value="Print" name="B1" onClick="window.print()">
          <input type="button"  value="Send Order" name="order" onClick="<?php mail($to,$subject,$contents,$headers); ?>">
        </p>
      </form>
    </td>
  </tr>
</table>

</body>
       </center>
</html>